<?php
require_once("conf/configuration.inc");

// Imagen original
$source = imagecreatefromjpeg(IMAGES_DIR.$_GET["s"]."/".$_GET["f"]);
$sourceWidth = imagesx($source);
$sourceHeight = imagesy($source);

// Imagen redimensionada al ancho de la miniatura
$thumbWidth = $_GET["w"];
$thumbHeight = ceil($sourceHeight * $thumbWidth / $sourceWidth);
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $sourceWidth, $sourceHeight);

// Imagen cortada al alto de la miniatura
$cropHeight = !empty($_GET["h"]) ? $_GET["h"] : $thumbHeight;
$crop = imagecreatetruecolor($thumbWidth, $cropHeight);
imagecopy($crop, $thumb, 0, 0, 0, 0, $thumbWidth, $cropHeight);

header("content-type: image/jpeg");
imagejpeg($crop, null, 100);
?> 
